package com.sanpu.kxe.business.main.adapter;

import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sanpu.kxe.R;
import com.sanpu.kxe.business.main.bean.ProfitsOutput;
import com.sanpu.kxe.common.enums.Level;
import com.sanpu.kxe.module.roundview.RoundLinearLayout;

import java.util.ArrayList;

/**
 * Description：我的团队列表（收益）
 * Created by 薛勇军 on 2018/8/8.
 */

public class MyProfitsAdapter extends BaseQuickAdapter<ProfitsOutput, BaseViewHolder> {

    private int mCurLvl;

    public MyProfitsAdapter(int mCurLvl) {
        super(R.layout.item_team, new ArrayList<ProfitsOutput>());
        this.mCurLvl = mCurLvl;
    }

    @Override
    protected void convert(BaseViewHolder helper, ProfitsOutput item) {
        if (item != null) {
            int count = item.getRefCount();
            helper.setText(R.id.count, "推荐人数" + count + "")
                    .setText(R.id.name, TextUtils.isEmpty(item.getuAccountName()) ? "" : item.getuAccountName())
                    .setText(R.id.amount, Html.fromHtml("产生佣金<font color='#FF9F23'>" +
                            item.getAccRebAmt() + "元</font>"))
                    .setText(R.id.time, TextUtils.isEmpty(item.getuCreateTime()) ? "" : item.getuCreateTime())
                    .setGone(R.id.auth_flag, "1".equals(item.getRlAuthFlg()));

            TextView vNameTv = helper.getView(R.id.vNameTv);
            vNameTv.setVisibility(View.GONE);
            if ("1".equals(item.getRlAuthFlg())) {
                if (!TextUtils.isEmpty(item.getCrpNm())) {
                    vNameTv.setText(item.getCrpNm());
                    vNameTv.setVisibility(View.VISIBLE);
                }
            }
            ImageView vItemArrow = helper.getView(R.id.item_arrow);
            vItemArrow.setVisibility(count != 0 ? View.VISIBLE : View.INVISIBLE);
            RoundLinearLayout vLevelLayout = helper.getView(R.id.level_layout);
            TextView vLevel = helper.getView(R.id.level);
            try {
                Level level = Level.values()[item.getUserLvl() - 1];
                vLevel.setText(level.getTitle());
                vLevelLayout.setVisibility(item.getUserLvl() > 1 ? View.VISIBLE : View.GONE);
                vLevelLayout.getDelegate().setBackgroundColor(ContextCompat.getColor(mContext, level.getColorRes()));
                if (mCurLvl >= 2) {vItemArrow.setVisibility(View.GONE);}
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
